/**
 * 
 */
package idv.takeshi.software.productline.bookstore.application.service.dto;

import idv.takeshi.software.productline.bookstore.domain.model.order.CreditCard;
import idv.takeshi.software.productline.bookstore.domain.model.order.CreditCardType;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import org.apache.commons.lang.Validate;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * A data-transfer Object for credit card model.
 * @author takeshi
 *
 */
public class CreditCardDto {
	
	@Pattern(regexp = ".+")
	@NotNull
	private String payerName;
	
	@Pattern(regexp = "(VISA|MASTER_CARD|JCB)")
	@NotNull
	private String creditCardType;
	
	@Pattern(regexp = "\\d{4,4}+")
	@NotNull
	private String creditCardNumber1;
	
	@Pattern(regexp = "\\d{4,4}+")
	@NotNull
	private String creditCardNumber2;
	
	@Pattern(regexp = "\\d{4,4}+")
	@NotNull
	private String creditCardNumber3;
	
	@Pattern(regexp = "\\d{4,4}+")
	@NotNull
	private String creditCardNumber4;
	
	@Pattern(regexp = "\\d{2,2}+")
	@NotNull
	private String validMonth;
	
	@Pattern(regexp = "\\d{2,2}+")
	@NotNull
	private String validYear;
	
	@Pattern(regexp = "\\d{3,3}+")
	@NotNull
	private String securityCode;
	
	@Pattern(regexp = ".+")
	@NotNull
	private String previousPath;
	
	/**
	 * Fill info to credit card model.
	 * @param creditCard
	 */
	public void loadModel(CreditCard creditCard){
		Validate.notNull(creditCard, "creditCard shall always not be null");
		creditCard.setPayerName(payerName);
		creditCard.setCreditCardType(CreditCardType.valueOf(this.creditCardType));
		creditCard.setCreditCardNumber(creditCardNumber1 + creditCardNumber2 + creditCardNumber3 + creditCardNumber4);
		creditCard.setValidMonth(validMonth);
		creditCard.setValidYear(validYear);
		creditCard.setSecurityCode(securityCode);
	}
	

	/**
	 * @return the payerName
	 */
	public String getPayerName() {
		return payerName;
	}

	/**
	 * @param payerName the payerName to set
	 */
	public void setPayerName(String payerName) {
		this.payerName = payerName;
	}

	/**
	 * @return the creditCardType
	 */
	public String getCreditCardType() {
		return creditCardType;
	}

	/**
	 * @param creditCardType the creditCardType to set
	 */
	public void setCreditCardType(String creditCardType) {
		this.creditCardType = creditCardType;
	}

	/**
	 * @return the creditCardNumber1
	 */
	public String getCreditCardNumber1() {
		return creditCardNumber1;
	}

	/**
	 * @param creditCardNumber1 the creditCardNumber1 to set
	 */
	public void setCreditCardNumber1(String creditCardNumber1) {
		this.creditCardNumber1 = creditCardNumber1;
	}

	/**
	 * @return the creditCardNumber2
	 */
	public String getCreditCardNumber2() {
		return creditCardNumber2;
	}

	/**
	 * @param creditCardNumber2 the creditCardNumber2 to set
	 */
	public void setCreditCardNumber2(String creditCardNumber2) {
		this.creditCardNumber2 = creditCardNumber2;
	}

	/**
	 * @return the creditCardNumber3
	 */
	public String getCreditCardNumber3() {
		return creditCardNumber3;
	}

	/**
	 * @param creditCardNumber3 the creditCardNumber3 to set
	 */
	public void setCreditCardNumber3(String creditCardNumber3) {
		this.creditCardNumber3 = creditCardNumber3;
	}

	/**
	 * @return the creditCardNumber4
	 */
	public String getCreditCardNumber4() {
		return creditCardNumber4;
	}

	/**
	 * @param creditCardNumber4 the creditCardNumber4 to set
	 */
	public void setCreditCardNumber4(String creditCardNumber4) {
		this.creditCardNumber4 = creditCardNumber4;
	}

	/**
	 * @return the validMonth
	 */
	public String getValidMonth() {
		return validMonth;
	}

	/**
	 * @param validMonth the validMonth to set
	 */
	public void setValidMonth(String validMonth) {
		this.validMonth = validMonth;
	}

	/**
	 * @return the validYear
	 */
	public String getValidYear() {
		return validYear;
	}

	/**
	 * @param validYear the validYear to set
	 */
	public void setValidYear(String validYear) {
		this.validYear = validYear;
	}

	/**
	 * @return the securityCode
	 */
	public String getSecurityCode() {
		return securityCode;
	}

	/**
	 * @param securityCode the securityCode to set
	 */
	public void setSecurityCode(String securityCode) {
		this.securityCode = securityCode;
	}

	/**
	 * @return the previousPath
	 */
	public String getPreviousPath() {
		return previousPath;
	}

	/**
	 * @param previousPath the previousPath to set
	 */
	public void setPreviousPath(String previousPath) {
		this.previousPath = previousPath;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
	}
	
}
